package pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;

/**
 * Created by DN on 22.05.2014.
 */
public class HomePage {
    private final String URL = "http://rozetka.com.ua/";
    public WebDriver driver;

    protected By notebooks = By.id("computers-notebooks");
    protected By telphons = By.id("phones-mp3-gps");
    protected By tv = By.id("tv-photo-video");
    protected By technick = By.id("bt");
    protected By turism = By.id("outdoorsman");
    protected By children = By.id("kids");
    protected By garden = By.id("house_garden");
    protected By auto = By.id("273290");
    protected By avia = By.id("fatmenu_14");
    protected By shoose = By.id("shoes");

    public HomePage (WebDriver driver)
    {
        this.driver = driver;
        //PageFactory.initElements(driver, this);
    }

    public void open()
    {
        driver.get(URL);
    }

    public WebElement getMenuItem(String name)
    {
        WebDriverWait wait = new WebDriverWait(driver, 5);
        wait.until(ExpectedConditions.elementToBeClickable(notebooks));
        if (name == "notebooks")
            return driver.findElement(notebooks);
        else if (name == "telphons")
            return driver.findElement(telphons);
        else if (name == "tv")
            return driver.findElement(tv);
        else if (name == "technick")
            return driver.findElement(technick);
        else if (name == "turism")
            return driver.findElement(turism);
        else if (name == "children")
            return driver.findElement(children);
        else if (name == "garden")
            return driver.findElement(garden);
        else if (name == "auto")
            return driver.findElement(auto);
        else if (name == "avia")
            return driver.findElement(avia);
        else if (name == "shoose")
            return driver.findElement(shoose);
        else
            return null;
    }
}
